home *** CD-ROM | disk | FTP | other *** search
- /* -----------------------------------------------------------------------------------
- -----------------------------------------------------------------------------------
- Lighting Demo.c
-
- by Brian Roddy
-
- 4/21/97
-
- This demo shows off the tinting and translucency functionality. Move the cursor
- to move around the light source, the blue ball. The diamonds will bounce and
- their light level is affected by the light level of the tile they are over. Light
- fades slowly away as the light source is moved.
-
- Hitting the space bar will switch the sprites between being opaque and translucent.
-
- Note that translucency will only run properly in 256 or Thousands of colors.
-
- This source code is available for free use. Crediting me would be nice, but
- isn't necessary.
- -----------------------------------------------------------------------------------
- ----------------------------------------------------------------------------------- */
-
-
- #include <SWIncludes.h>
- #include <SWGameUtils.h>
- #include <SWDitherDown.h>
- #include <SWFPSReport.h>
-
- #include "SWApplication.h"
- #include "Tiling.h"
- #include "Lighting Demo.h"
- #include "SWTinting.h"
- #include "SWTranslucentBlitters.h"
-
-
- #define kFullScreenWindow true // Makes the window fill the screen
- #define kSyncToVBL false // Syncs animation to VBL
- #define kWorldRectInset 0 // Makes SpriteWorld smaller than window
- #define kMaxFPS 0 // Set to 0 for unrestricted speed
-
- #define kNumDiamonds 20 // Number of diamonds
- #define kMaxDiamondMoveDelta 5 // Max speed for the diamonds
-
- #define kTileWidth 32 // Don't change these unless you
- #define kTileHeight 32 // change the resource as well.
-
- //--------------------------------
- // For testing Translucency
- //--------------------------------
- #define kBallTranslucencyLevel 0 // Try 0-8. 0 means solid (not translucent).
- #define kDiamondTranslucencyLevel 0 // 1-8 specify translucent.
- // Higher means more opaque.
- //--------------------------------
- #define kNumberOfTicksBeforeFade 6
- Boolean BigLightOn = false; // If this is true, the ball emanate a really big light.
- // Toggle with the L key.
-
- /***********/
- /* Globals */
- /***********/
-
- SpriteWorldPtr gSpriteWorldP;
-
- SpriteLayerPtr gDiamondSpriteLayerP;
-
- TileMapStructPtr gTileMapStructP;
- SpritePtr gBallSpriteP;
- WindowPtr gWindowP;
-
- DrawProcPtr gSpriteDrawProc;
- short gNumTileMapRows, gNumTileMapCols;
-
-
- ///--------------------------------------------------------------------------------------
- // Main
- ///--------------------------------------------------------------------------------------
-
- void main( void )
- {
- Initialize(kNumberOfMoreMastersCalls);
-
- if (SWHasSystem7())
- {
- SetCursor(*GetCursor(watchCursor));
-
- CreateSpriteWorld();
- SetUpTiling();
- CreateSprites();
-
- SetCursor(&qd.arrow);
- HideCursor();
-
-
- SetUpAnimation();
- RunAnimation();
- ShutDown();
- }
- else
- {
- CantRunOnThisMachine();
- }
- }
-
-
- ///--------------------------------------------------------------------------------------
- // CreateSpriteWorld
- ///--------------------------------------------------------------------------------------
-
- void CreateSpriteWorld( void )
- {
- Rect offscreenRect, worldRect, windRect;
- RgnHandle mBarUpdateRgn;
- short depth;
- OSErr err;
-
- gWindowP = GetNewCWindow(kWindowResID, NULL, (WindowPtr)-1L);
-
- if (gWindowP != NULL)
- {
- depth = GetDepthFromWindow(gWindowP);
- if ( depth < 8 || depth > 16 )
- {
- SetCursor(&qd.arrow);
- StopAlert(130, NULL);
- ExitToShell();
- }
-
- if (kFullScreenWindow == true)
- {
- SizeWindow(gWindowP, qd.screenBits.bounds.right,
- qd.screenBits.bounds.bottom, false);
- MoveWindow(gWindowP, 0, 0, false);
- }
- else
- {
- // Center window in screen
- windRect = gWindowP->portRect;
- CenterRect(&windRect, &qd.screenBits.bounds);
- MoveWindow(gWindowP, windRect.left, windRect.top, false);
- }
-
- ShowWindow(gWindowP);
- SetPort(gWindowP);
- mBarUpdateRgn = SWHideMenuBar(gWindowP); // Must be done *after* showing window!
- EraseRgn(mBarUpdateRgn);
-
- }
- else
- CantFindResource();
-
-
- err = SWEnterSpriteWorld();
- FatalError(err);
-
-
- worldRect = gWindowP->portRect;
- InsetRect(&worldRect, kWorldRectInset, kWorldRectInset);
-
-
- // Set size of offscreen area
- offscreenRect = worldRect;
- OffsetRect(&offscreenRect, -offscreenRect.left, -offscreenRect.top);
-
-
- // Make offscreen area evenly divisible by tile width & height
- if ( (offscreenRect.right/kTileWidth)*kTileWidth != offscreenRect.right)
- offscreenRect.right = (offscreenRect.right/kTileWidth)*kTileWidth + kTileWidth;
-
- if ( (offscreenRect.bottom/kTileHeight)*kTileHeight != offscreenRect.bottom)
- offscreenRect.bottom = (offscreenRect.bottom/kTileHeight)*kTileHeight + kTileHeight;
-
-
- gNumTileMapRows = offscreenRect.bottom / kTileHeight;
- gNumTileMapCols = offscreenRect.right / kTileWidth;
-
-
- err = SWCreateSpriteWorldFromWindow(&gSpriteWorldP, (CWindowPtr)gWindowP,
- &worldRect, &offscreenRect, 0);
- FatalError(err);
-
- if (gSpriteWorldP->pixelDepth == 16)
- gSpriteDrawProc = BlitPixieAllBitMaskDrawProc;
- else if (gSpriteWorldP->pixelDepth == 8)
- gSpriteDrawProc = BlitPixie8BitMaskDrawProc;
- else
- gSpriteDrawProc = SWStdSpriteDrawProc;
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SetUpTiling
- ///--------------------------------------------------------------------------------------
-
- // We have to set aside kNumberOfBrightnessLevels number of tiles
- // for each tile graphic we want to display.
- #define kWallTile (kNumberOfBrightnessLevels * 0)
- #define kBoardTile (kNumberOfBrightnessLevels * 1)
- #define kMaxNumTiles (kNumberOfBrightnessLevels * 2)
-
- void SetUpTiling( void )
- {
- short row, col;
- OSErr err;
-
- // Must be done before we can load the tiles.
- err = SWInitTiling(gSpriteWorldP, kTileHeight, kTileWidth, kMaxNumTiles);
- FatalError(err);
-
- err = SWCreateTileMap(&gTileMapStructP, gNumTileMapRows, gNumTileMapCols);
- FatalError(err);
-
- SWInstallTileMap(gSpriteWorldP, gTileMapStructP, 0);
-
-
- // Create the wall tiles
- CreateTileBrightnessSetFromCicnResource(
- gSpriteWorldP,
- kWallTile, // tileID
- 200, // CICN resource ID
- kNoMask); // maskType
-
- // Create the board tiles
- CreateTileBrightnessSetFromCicnResource(
- gSpriteWorldP,
- kBoardTile, // tileID
- 300, // CICN resource ID
- kNoMask); // maskType
-
- // Initialize the values in the tileMap
- for (row = 0; row < gNumTileMapRows; row++)
- {
- for (col = 0; col < gNumTileMapCols; col++)
- {
- if (row == 0 || col == 0 || row == gNumTileMapRows-1 || col == gNumTileMapCols-1)
- gTileMapStructP->tileMap[row][col] = kWallTile;
- else
- gTileMapStructP->tileMap[row][col] = kBoardTile;
- }
- }
- }
-
-
- ///--------------------------------------------------------------------------------------
- // CreateSprites
- ///--------------------------------------------------------------------------------------
-
- void CreateSprites( void )
- {
- SpritePtr otherSpriteP;
- SpritePtr diamondSpriteP;
- SpritePtr tempSpriteP;
- short spriteNum;
- Point moveDelta, mousePoint;
- Rect moveBounds;
- OSErr err;
-
-
- // Create the sprite layer
- err = SWCreateSpriteLayer(&gDiamondSpriteLayerP);
- FatalError(err);
-
-
- moveBounds = gSpriteWorldP->backRect;
- InsetRect(&moveBounds, 40, 40);
-
- // create and set up the diamond sprites
- for (spriteNum = 0; spriteNum < kNumDiamonds; spriteNum++)
- {
- if (spriteNum == 0)
- {
- err = CreateSpriteBrightnessSetFromCicnResource (
- gSpriteWorldP,
- &diamondSpriteP,
- NULL, // pointer to memory for sprite
- 130, // cicn resource id
- kFatMask); // mask type
- FatalError(err);
- tempSpriteP = diamondSpriteP;
- }
- else if (spriteNum == 1)
- {
- err = CreateSpriteBrightnessSetFromCicnResource (
- gSpriteWorldP,
- &otherSpriteP,
- NULL, // pointer to memory for sprite
- 129, // cicn resource id
- kFatMask); // mask type
- FatalError(err);
- tempSpriteP = otherSpriteP;
- }
- else
- {
- err = SWCloneSprite(((spriteNum & 1) ? diamondSpriteP : otherSpriteP), &tempSpriteP, NULL);
- FatalError(err);
- }
-
-
- SWSetSpriteMoveBounds(tempSpriteP, &moveBounds);
- SWSetSpriteMoveProc(tempSpriteP, DiamondSpriteMoveProc);
- SWSetSpriteFrameTime(tempSpriteP, 2000);
-
- SWSetSpriteLocation(tempSpriteP,
- GetRandom(40, gSpriteWorldP->backRect.right-80),
- GetRandom(40, gSpriteWorldP->backRect.bottom-80));
-
- do
- {
- moveDelta.h = GetRandom(-kMaxDiamondMoveDelta, kMaxDiamondMoveDelta);
- moveDelta.v = GetRandom(-kMaxDiamondMoveDelta, kMaxDiamondMoveDelta);
- } while (!moveDelta.v || !moveDelta.h);
-
- SWAddSprite(gDiamondSpriteLayerP, tempSpriteP);
- SWSetSpriteMoveDelta(tempSpriteP, moveDelta.h, moveDelta.v);
- SWSetSpriteDrawProc(tempSpriteP, gSpriteDrawProc);
- SWSetSpriteTranslucencyLevel(tempSpriteP, kDiamondTranslucencyLevel);
- err = SWSetSpriteTranslucencyLevel(tempSpriteP, kDiamondTranslucencyLevel);
- FatalError(err);
- }
-
-
- // Create the ball sprite
- //err = CreateSpriteBrightnessSetFromCicnResource(gSpriteWorldP, &gBallSpriteP, NULL,
- // 128, kFatMask);
- err = SWCreateSpriteFromCicnResource(gSpriteWorldP, &gBallSpriteP, NULL,
- 500, 10, kFatMask);
- FatalError(err);
- SWSetSpriteFrameAdvance(gBallSpriteP, 1);
- SWSetSpriteFrameAdvanceMode(gBallSpriteP, kSWWrapAroundMode);
- SWSetSpriteFrameRange(gBallSpriteP, 0, 9);
- SWSetSpriteFrameTime(gBallSpriteP, 100);
-
-
- // Set up the ball sprite
- SWAddSprite(gDiamondSpriteLayerP, gBallSpriteP);
- SWSetSpriteMoveProc(gBallSpriteP, MouseSpriteMoveProc);
- SWSetSpriteDrawProc(gBallSpriteP, gSpriteDrawProc);
- SWSetSpriteTranslucencyLevel(gBallSpriteP, kBallTranslucencyLevel);
- GetMouse(&mousePoint);
- SWSetSpriteLocation(gBallSpriteP, mousePoint.h - 20, mousePoint.v - 20);
-
- SWAddSpriteLayer(gSpriteWorldP, gDiamondSpriteLayerP);
-
- SWLockSpriteWorld(gSpriteWorldP);
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SetUpAnimation
- ///--------------------------------------------------------------------------------------
-
- void SetUpAnimation( void )
- {
- OSErr err;
-
- SWSetSpriteWorldMaxFPS(gSpriteWorldP, kMaxFPS);
- SWSyncSpriteWorldToVBL(gSpriteWorldP, kSyncToVBL);
- SWSetCleanUpSpriteWorld(gSpriteWorldP);
-
- if (gSpriteWorldP->pixelDepth == 16)
- {
- err = SWCreate16BitTranslucencyTable();
- FatalError(err);
- SWSetSpriteWorldOffscreenDrawProc(gSpriteWorldP, BlitPixieAllBitRectDrawProc);
- SWSetSpriteWorldScreenDrawProc(gSpriteWorldP, BlitPixieAllBitRectDrawProc);
- SWSetPartialMaskDrawProc(gSpriteWorldP, BlitPixieAllBitPartialMaskDrawProc);
- }
- else
- {
- err = SWLoadOrCreate8BitTranslucencyTable(2);
- FatalError(err);
- SWSetSpriteWorldOffscreenDrawProc(gSpriteWorldP, BlitPixie8BitRectDrawProc);
- SWSetSpriteWorldScreenDrawProc(gSpriteWorldP, BlitPixie8BitRectDrawProc);
- SWSetPartialMaskDrawProc(gSpriteWorldP, BlitPixie8BitPartialMaskDrawProc);
- }
-
- ForeColor(blackColor);
- BackColor(whiteColor);
-
- SWDrawTilesInBackground(gSpriteWorldP);
- SWLockSpriteWorld(gSpriteWorldP);
- SWUpdateSpriteWorld(gSpriteWorldP, true);
- }
-
-
- ///--------------------------------------------------------------------------------------
- // RunAnimation
- ///--------------------------------------------------------------------------------------
-
- void RunAnimation( void )
- {
- unsigned long frames;
-
- frames = 0;
- StartTimer();
-
- FatalError( SWStickyError() ); // Make sure no errors got past us during setup
-
- while (!Button())
- {
- SWProcessSpriteWorld(gSpriteWorldP);
- FatalError( SWStickyError() ); // Make sure no errors occurred in a MoveProc, etc.
- SWAnimateSpriteWorld(gSpriteWorldP);
-
- if (gSpriteWorldP->frameHasOccurred)
- frames++;
- }
-
- SWShowMenuBar(gWindowP);
- ShowResults(frames);
- }
-
-
- ///--------------------------------------------------------------------------------------
- // ShutDown (clean up and dispose of the SpriteWorld)
- ///--------------------------------------------------------------------------------------
-
- void ShutDown( void )
- {
- SWUnlockSpriteWorld(gSpriteWorldP);
- SWDisposeSpriteWorld(&gSpriteWorldP);
- SWExitSpriteWorld();
- SWDispose8BitTranslucencyTable();
- SWDispose16BitTranslucencyTable();
- FlushEvents(everyEvent, 0);
- ShowCursor();
- }
-
-
- ///--------------------------------------------------------------------------------------
- // RandomNumber
- ///--------------------------------------------------------------------------------------
-
- // A basic random number generator
- short RandomNumber(short inMax)
- {
- short retVal = Random() * (long)inMax / 32767;
- if (retVal < 0) retVal = - retVal;
- return retVal;
- }
-
- //-----
- // some globals for our ball sprite move routine
- unsigned long lastTickCount = 0; // used in our fade routine, see below.
- int lastRow = -13; // start these offscreen so there's no
- int lastCol = -13; // drawing problems
-
- //---- The ball sprite routine
- // It tracks the mouse and it lights up the area it's over.
- // Also checks for hitting the spacebar to change the translucency level.
- SW_FUNC void MouseSpriteMoveProc(SpritePtr srcSpriteP)
- {
- Point mousePoint;
- int row, col;
-
- unsigned long curTickCount = TickCount();
- EventRecord event;
- short theChar;
-
- // Move the ball sprite
- GetMouse(&mousePoint);
- SWMoveSprite(srcSpriteP, mousePoint.h - 20, mousePoint.v - 20);
-
- // Every few ticks, lower the level of the light of all of the tiles.
- // This gives us the slow fade effect as you move around, as well
- // as the flicker of the the light source.
- TickCount();
- if (curTickCount - lastTickCount >= kNumberOfTicksBeforeFade) {
- LowerTileBrightnessLevels(gSpriteWorldP);
- lastTickCount = curTickCount;
- }
-
- // Convert pixel row and col into tile row and col
- col = mousePoint.h / gSpriteWorldP->tileWidth;
- row = mousePoint.v / gSpriteWorldP->tileHeight;
-
- // If we have moved or if some random amount of time has passed
- // we need to redraw the light. Remember, the light is always
- // fading away after time.
- if ((lastCol != col) ||
- (lastRow != row) ||
- (RandomNumber(3) == 0)) {
-
- // Light up the tiles around the sprite. Light up the center sprite and
- // adjacent ones really bright, Light up the four diagonally adjacent ones
- // fairly bright.
-
- // Calculate the light levels
- int lightLevelBorder = (kNumberOfBrightnessLevels / 2) + RandomNumber(3);
- int lightLevelMiddle = lightLevelBorder; // + RandomNumber(2);
-
- // and light them up
- SetTileBrightnessLevel(gSpriteWorldP, 0, row - 1, col - 1, lightLevelBorder, false);
- SetTileBrightnessLevel(gSpriteWorldP, 0, row , col - 1, lightLevelMiddle, false);
- SetTileBrightnessLevel(gSpriteWorldP, 0, row + 1, col - 1, lightLevelBorder, false);
- SetTileBrightnessLevel(gSpriteWorldP, 0, row - 1, col , lightLevelMiddle, false);
- SetTileBrightnessLevel(gSpriteWorldP, 0, row , col , lightLevelMiddle, false);
- SetTileBrightnessLevel(gSpriteWorldP, 0, row + 1, col , lightLevelMiddle, false);
- SetTileBrightnessLevel(gSpriteWorldP, 0, row - 1, col + 1, lightLevelBorder, false);
- SetTileBrightnessLevel(gSpriteWorldP, 0, row , col + 1, lightLevelMiddle, false);
- SetTileBrightnessLevel(gSpriteWorldP, 0, row + 1, col + 1, lightLevelBorder, false);
-
- if (BigLightOn)
- { /// If BigLightOn is true then we make a really big light that
- /// lights up a 5x5 area of tiles rather than 3x3
- int lightLevelEdgeCorner = lightLevelBorder - 2;
- int lightLevelEdgeNearCorner = lightLevelBorder - 1;
- int lightLevelEdge = lightLevelBorder - 1;
-
- SetTileBrightnessLevel(gSpriteWorldP, 0, row - 2, col - 2, lightLevelEdgeCorner, false);
- SetTileBrightnessLevel(gSpriteWorldP, 0, row + 2, col - 2, lightLevelEdgeCorner, false);
- SetTileBrightnessLevel(gSpriteWorldP, 0, row - 2, col + 2, lightLevelEdgeCorner, false);
- SetTileBrightnessLevel(gSpriteWorldP, 0, row + 2, col + 2, lightLevelEdgeCorner, false);
- SetTileBrightnessLevel(gSpriteWorldP, 0, row - 1, col - 2, lightLevelEdgeNearCorner, false);
- SetTileBrightnessLevel(gSpriteWorldP, 0, row , col - 2, lightLevelEdge, false);
- SetTileBrightnessLevel(gSpriteWorldP, 0, row + 1, col - 2, lightLevelEdgeNearCorner, false);
- SetTileBrightnessLevel(gSpriteWorldP, 0, row - 1, col + 2, lightLevelEdgeNearCorner, false);
- SetTileBrightnessLevel(gSpriteWorldP, 0, row , col + 2, lightLevelEdge, false);
- SetTileBrightnessLevel(gSpriteWorldP, 0, row + 1, col + 2, lightLevelEdgeNearCorner, false);
- SetTileBrightnessLevel(gSpriteWorldP, 0, row - 2, col - 1, lightLevelEdgeNearCorner, false);
- SetTileBrightnessLevel(gSpriteWorldP, 0, row - 2, col , lightLevelEdge, false);
- SetTileBrightnessLevel(gSpriteWorldP, 0, row - 2, col + 1, lightLevelEdgeNearCorner, false);
- SetTileBrightnessLevel(gSpriteWorldP, 0, row + 2, col - 1, lightLevelEdgeNearCorner, false);
- SetTileBrightnessLevel(gSpriteWorldP, 0, row + 2, col , lightLevelEdge, false);
- SetTileBrightnessLevel(gSpriteWorldP, 0, row + 2, col + 1, lightLevelEdgeNearCorner, false);
- }
-
- // Light the sprite to the same level as the one it's over.
- //SetSpriteBrightnessLevel(
- // srcSpriteP,
- // GetTileBrightnessLevel(gSpriteWorldP, 0, row, col));
-
- // Save our current row and column so we can detect if we move.
- lastRow = row;
- lastCol = col;
- }
-
- // Toggle between translucent and opaque if the spacebar was hit
- while ( GetOSEvent(keyDownMask, &event) )
- {
- theChar = (event.message & charCodeMask);
-
- if ((theChar == 'l') || (theChar == 'L')) {
- BigLightOn = ! BigLightOn;
- }
-
- if ((theChar == '-') || (theChar == '_')) {
- short tileRow, tileCol;
-
- backgroundTileMinimumLightLevel--;
- if (backgroundTileMinimumLightLevel < 0)
- backgroundTileMinimumLightLevel = 0;
-
- // force a redraw
- for (tileRow = 0; tileRow < gSpriteWorldP->tileLayerArray[0]->numRows; tileRow++)
- for (tileCol = 0; tileCol < gSpriteWorldP->tileLayerArray[0]->numCols; tileCol++)
- SetTileBrightnessLevel(gSpriteWorldP, 0, tileRow, tileCol,
- backgroundTileMinimumLightLevel, false);
- }
- if ((theChar == '=') || (theChar == '+')) {
- short tileRow, tileCol;
-
- backgroundTileMinimumLightLevel++;
- if (backgroundTileMinimumLightLevel >= kNumberOfBrightnessLevels)
- backgroundTileMinimumLightLevel = kNumberOfBrightnessLevels - 1;
-
- // force a redraw
- for (tileRow = 0; tileRow < gSpriteWorldP->tileLayerArray[0]->numRows; tileRow++)
- for (tileCol = 0; tileCol < gSpriteWorldP->tileLayerArray[0]->numCols; tileCol++)
- SetTileBrightnessLevel(gSpriteWorldP, 0, tileRow, tileCol,
- backgroundTileMinimumLightLevel, false);
- }
-
- if (theChar == ' ')
- {
- SpritePtr curSprite;
- int curLevel;
-
- // Increment the current translucency level (1 through kNumberOfTranslucencyLevels).
- // If we go to high, wrap back down to opacity (level 0).
- curLevel = SWGetSpriteTranslucencyLevel(srcSpriteP);
- curLevel ++;
-
-
- if (gSpriteWorldP->pixelDepth == 16) {
- if (curLevel >= kNumberOf16BitTranslucencyLevels) curLevel = 0;
- } else {
- if (curLevel > gNumberOf8BitTranslucencyLevels) curLevel = 0;
- }
-
- // Set all the diamonds to that translucency level
- curSprite = gDiamondSpriteLayerP->headSpriteP;
- while (curSprite != NULL) {
- SWSetSpriteTranslucencyLevel(curSprite, curLevel);
- curSprite = curSprite->nextSpriteP;
- }
-
- // Set the ball to that translucency level
- SWSetSpriteTranslucencyLevel(srcSpriteP, curLevel);
-
- // And draw our little box that says the current level.
- DrawMyLevel(curLevel);
- }
- }
- }
-
-
- // A hack to draw the text that says the level of translucency
- void DrawMyLevel (short Number) {
- GWorldPtr oldGWld;
- GDHandle oldGDH;
- Rect tempRect;
-
- // Save the old state
- GetGWorld( &oldGWld, &oldGDH );
-
- // Set the drawing port
- SetGWorld(gSpriteWorldP->windowFrameP->framePort, nil);
-
- // Draw a green box to put the text on.
- PenNormal();
- ForeColor(greenColor);
- tempRect.top = tempRect.left = 10;
- tempRect.right = 95;
- tempRect.bottom = 35;
- PaintRect(&tempRect);
-
- // Draw the text
- ForeColor(whiteColor);
- BackColor(blackColor);
- MoveTo(20, 30);
- TextSize(9);
- if (Number == 0)
- DrawString("\pOpaque");
- else
- DrawString("\pTranslucent");
-
- // And if it's translucent say how much
- if (Number > 0) {
- Str255 NumberString;
- NumToString(Number, NumberString);
- DrawString("\p ");
- DrawString(NumberString);
- }
-
- // Restore the old state
- SetGWorld( oldGWld, oldGDH );
- }
-
- ///--------------------------------------------------------------------------------------
- // DiamondSpriteMoveProc
- ///--------------------------------------------------------------------------------------
-
- // Diamonds bounce around and set their light level based on the light level of
- // the tile beneath them.
-
- SW_FUNC void DiamondSpriteMoveProc(SpritePtr diamondSpriteP)
- {
- int hh, vv, row, col, tileLightLevel;
-
- // Move and bounce the diamond
- SWOffsetSprite(diamondSpriteP, diamondSpriteP->horizMoveDelta, diamondSpriteP->vertMoveDelta);
- SWBounceSprite(diamondSpriteP);
-
- // Find the center of the diamond
- hh = diamondSpriteP->destFrameRect.left;
- vv = diamondSpriteP->destFrameRect.top;
- hh += ((diamondSpriteP->destFrameRect.right - diamondSpriteP->destFrameRect.left) / 2);
- vv += ((diamondSpriteP->destFrameRect.bottom - diamondSpriteP->destFrameRect.top) / 2);
-
- // Find the associated tile row and column
- col = hh / gSpriteWorldP->tileWidth;
- row = vv / gSpriteWorldP->tileHeight;
-
- // And set the sprite's light level to the tiles light level.
- tileLightLevel = GetTileBrightnessLevel(gSpriteWorldP, 0, row, col);
- SetSpriteBrightnessLevel(diamondSpriteP, tileLightLevel);
- }
-
-